package activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.liuyujia.activity.R;

import java.util.Calendar;

/**
 * Created by liuyujia on 2015/3/30.
 */
public class BaseActivity extends Activity {

    private RelativeLayout mProgressDialog;
    protected int displayHeight;
    protected int displayWidth;
    private Calendar calendar;
    private TextView title;
    private String time;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        displayWidth = dm.widthPixels; // 得到宽度
        displayHeight = dm.heightPixels; // 得到高度
        LayoutInflater li = LayoutInflater.from(this);
        mProgressDialog = (RelativeLayout) li.inflate(R.layout.dialog_progressbar, null);
        title = (TextView) mProgressDialog.findViewById(R.id.tv_loading_title);
    }
    public void showProgressDialog(String titleString) {
        if (titleString != null) {
            // mProgressDialog.setMessage(title);
            title.setText(titleString);
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                ViewGroup parent = (ViewGroup) mProgressDialog.getParent();
                if (parent != null) {
                    parent.removeView(mProgressDialog);
                }
                ViewGroup top = (ViewGroup) getWindow().getDecorView();
                top.addView(mProgressDialog);
            }
        });
    }
    public void hideProgressDialog() {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                ViewGroup parent = (ViewGroup) mProgressDialog.getParent();
                if (parent != null) {
                    parent.removeView(mProgressDialog);
                }
            }
        });
    }
}
